/***************************************************************************
 创建者: 华磊
 开始时间: 2018.8.14
 copyright: (C) 华友高科
 修改说明: (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 example (1) hualei 2017.5.8 类的具体实现代码编写

 ***************************************************************************/
#include "regdata.h"
#include "messagelog.h"
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>

RegData::RegData()
{

    versionInfo.componentName="RegData";
    versionInfo.componentVersion="V1.0";
    versionInfo.publishDate="2018.10.27";

    pthread_mutexattr_init(&regAttr);
    pthread_mutexattr_setprotocol(&regAttr,PTHREAD_PRIO_INHERIT);
    pthread_mutex_init(&regThreadLock,&regAttr);

    robotId = 1;

    regRInitialOk=false;
    regTimerInitialOk=false;
    regPrInitialOk=false;
    regPlInitialOk=false;

    timerCount.resize(D_ROBOT_TIMER_REG_SIZE);
    memset(timerCount.begin(),0,D_ROBOT_TIMER_REG_SIZE);

    startTime.resize(D_ROBOT_TIMER_REG_SIZE);
    endTime.resize(D_ROBOT_TIMER_REG_SIZE);

    timerProcessType.resize(D_ROBOT_TIMER_REG_SIZE);
    memset(timerProcessType.begin(),0,D_ROBOT_TIMER_REG_SIZE);

    timeValStartTime = {0,0};
    timeValEndTime = {0,0};

    thisTimeProduction_old=0;
    accumulatedProduction_old=0;
    workpieceRatio_old=0;

    //    Init();
}



int RegData::Init(int startType)
{
    //md5Instance = MD5Check::getInstance();

    qDebug() <<"********* RegData::Init*********"<<startType<<"\n";
    if(ROBOT_HOT_START == startType)
    {
        readRegRValue_fromFile();
        readRegPrValue_fromFile();
        readRegPlValue_fromFile();
        readRegTimerValue_fromFile();
    }
    else if(ROBOT_COOL_START == startType)
    {
        clearAllPlValue();
        clearAllRegRValue();
        clearAllPrValue();
        clearAllTimerValue();

    }
    else
    {
        qDebug()<<"startType="<<startType<<"不支持";
        addMsg(ENUM_MSG_ERROR, "RegData", "RegData", 3208, robotId);
    }
    //当前产量清空
    clearCurrentProduction();

}

int RegData::clearCurrentProduction()
{
    qDebug()<<"RegData::clearCurrentProduction";
    this->lock();
    if(regRValue.size()>=1)
    {
        regRValue[0]=0;

    }
    this->unlock();
    setRegTimer(0,TIMER_REG_PROCESS_RESET,0);
    return 1;

}

int RegData::clearAccumulatedProduction()
{
    qDebug()<<"RegData::clearAccumulatedProduction";
    this->lock();
    if(regRValue.size()>=2)
    {
        regRValue[0]=0;
        regRValue[1]=0;
    }
    this->unlock();
    setRegTimer(0,TIMER_REG_PROCESS_RESET,0);
    return 1;
}


int RegData::readVersion(std::vector <ComponentVersion> &componentVersionList)
{
    componentVersionList.push_back(versionInfo);
    return 1;
}

int RegData::getProduction(float &thisTimeProduction, float &accumulateProduction)
{
    if(this->trylock())
    {
        if(1<=regRValue.size())
        {
            thisTimeProduction=regRValue[0];
            accumulateProduction=regRValue[1];
            thisTimeProduction_old=thisTimeProduction;
            accumulatedProduction_old=accumulateProduction;
        }
        this->unlock();
        return 1;
    }
    else
    {
        thisTimeProduction=thisTimeProduction_old;
        accumulateProduction=accumulatedProduction_old;
    }
    return -1;
}

int RegData::getWorkPieceRatio(float &workpieceRatio)
{
    if(this->trylock())
    {
        if(regTimerValue.size()>=1 && regRValue.size()>=1)
        {
            workpieceRatio=regTimerValue[0]/regRValue[0];
            updateTimerRegisterValue_index(0);
            regTimerValue_old=regTimerValue[0];
        }

        this->unlock();
        return 1;
    }
    else
    {
        workpieceRatio=workpieceRatio_old;
        return 1;
    }
    return -1;
}

int RegData::updateControllerInfoLevel3(UpdateDataLv3 &updateDataLv3)
{
    if(this->trylock())
    {
        updateDataLv3.localRegister = regRValue.toStdVector();
        updateDataLv3.pointRegister = regPrValue.toStdVector();
        updateDataLv3.plRegister = regPlValue.toStdVector();
//        updateDataLv3.timerRegister = regTimerValue.toStdVector();
        updateTimerRegisterValue();


        updateDataLv3.timerRegister = regTimerValue.toStdVector();
        this->unlock();
    }
}

int RegData::updateTimerRegisterValue_index(int timerNum)
{
    gettimeofday(&timeValEndTime,NULL);
    endTime[timerNum] = timeValEndTime;

    float timeCount = 0.0;

    float tmp1 = endTime[timerNum].tv_sec - startTime[timerNum].tv_sec;
    float tmp2 =(endTime[timerNum].tv_usec - startTime[timerNum].tv_usec)/MICROSECOND_TIME ;

    timeCount = tmp1 + tmp2;

//   qDebug()  <<__FUNCTION__<<"=timerNum====" <<timerNum<<"***tmp1***"<<tmp1<<"***tmp2*****"<<tmp2<<"====timeCount====="<<timeCount<<"\n\n\n\n\n";

//    timeCount = programSet.endTime[timerNum].tv_sec + programSet.endTime[timerNum].tv_usec/MICROSECOND_TIME
//            - programSet.startTime[timerNum].tv_sec - programSet.startTime[timerNum].tv_usec/MICROSECOND_TIME;

    timerCount[timerNum] += timeCount ;
    startTime[timerNum] = timeValEndTime;
    regTimerValue[timerNum] = timerCount[timerNum];

    return 0;
}

int RegData::setRegTimer(int timerNum, int changeStatus, double countTimer)
{
    lock();
    if(TIMER_REG_PROCESS_START == changeStatus)
    {
         if((TIMER_REG_PROCESS_START == timerProcessType[timerNum])
                 ||(TIMER_REG_PROCESS_REG == timerProcessType[timerNum]))
         {

         }
         else
         {
             gettimeofday(&timeValStartTime,NULL);
             startTime[timerNum] = timeValStartTime;
             timerProcessType[timerNum] = TIMER_REG_PROCESS_START;
         }
     }
    else if(TIMER_REG_PROCESS_STOP == changeStatus)
    {
        if((TIMER_REG_PROCESS_STOP == timerProcessType[timerNum]))
        {

        }
        else
        {
            updateTimerRegisterValue_index(timerNum);
            timerProcessType[timerNum] = TIMER_REG_PROCESS_STOP;
        }
    }
     else if(TIMER_REG_PROCESS_RESET == changeStatus)//在ｓｔａｒｔ和Ｒｅｇ模式下都能ｒｅｓｅｔ
     {
 //                programSet.timerOverFlowType[timerNum] = TIMER_OVER_FLOW_NONE;

         gettimeofday(&timeValStartTime,NULL);

         timerCount[timerNum] = 0.0;
         startTime[timerNum] = timeValStartTime;
         endTime[timerNum] = timeValStartTime;
 //        programSet.timerProcessType[timerNum] = TIMER_PROCESS_RESET;
     }
   else if(TIMER_REG_PROCESS_REG == changeStatus)
    {
        timerCount[timerNum] = countTimer;
        gettimeofday(&timeValStartTime,NULL);
        startTime[timerNum] = timeValStartTime;
        endTime[timerNum] = timeValStartTime;
        timerProcessType[timerNum] = TIMER_REG_PROCESS_REG;
    }
    regTimerValue = timerCount;
    unlock();

    return 0;
}



int RegData::readRegRValue_fromFile()
{
    QString tmpName = D_TCRCONTROLLER_DATA_PATH;
    tmpName = tmpName+ROBOT_FLODER + QString::number(robotId);
    QString regRName = tmpName + R_REG_FILE;
    robotName = tmpName;

//    if(1!=readRegRFile_stream(regRName))
    if(1!=readRegRFile_json(regRName))
    {
        addMsg(ENUM_MSG_ERROR, "RegData", "RegData", 3200, robotId);
        regRInitialOk=false;
        return -1;
    }
    #ifdef D_USE_MD5_CHECK
    MD5Check md5Checker;
    if(-1==md5Checker.isMd5CheckOk(regRName,regRName+".md5"))
    {
        qDebug()<<"readRegRValue checkFile  R_REG_FILE error！";
        addMsg(ENUM_MSG_ERROR, "RegData", "RegData", 3201, robotId);
        regRInitialOk=false;

        return -1;
    }
    QFile::remove(regRName+".md5");
    #endif
    regRInitialOk=true;
    return 1;

}

int RegData::readRegRFile_stream(QString fileName)
{
    int returnFlag=-1;
    QFile file(fileName);
    if(this->lock())
    {
        if(file.exists())
        {
            if(file.open(QIODevice::ReadOnly))
            {
                QDataStream out(&file);
                out.setVersion(QDataStream::Qt_4_6);
                out >> regRValue;
                file.close();
                file.flush();//必须加，如果不加，可能关机的时候丢失文件内容。
            }
            returnFlag= 1;
        }
        else
        {
            regRValue.resize(D_ROBOT_REG_SIZE);
            returnFlag= -1;
        }
        this->unlock();
    }
    return returnFlag;
}

int RegData::readRegRFile_json(QString fileName)
{
    qDebug()<<"RegData::readRegRFile_json"<<fileName;
    regRValue.clear();
    int returnFlag=-1;
    QFile file(fileName);
    if(this->lock())
    {
        if(file.exists())
        {
            if(file.open(QIODevice::ReadOnly))
            {

                QByteArray receiveByteArry = file.read(file.bytesAvailable());
                QJsonParseError jsonError;
                QJsonDocument receiveJsonDoc = QJsonDocument::fromJson(receiveByteArry, &jsonError);
                if(jsonError.error != QJsonParseError::NoError )
                {
                  qDebug() << "readRegRFile_json JsonFile error "<<jsonError.error;
                  this->unlock();
                  return -2;
                }
                QJsonObject redeiveJsonObj = receiveJsonDoc.object();

                if(false==redeiveJsonObj.contains("regR_info"))
                {
                    this->unlock();
                    return -3;
                }
                QJsonObject obj_level1=redeiveJsonObj.value("regR_info").toObject();
                if(false==obj_level1.contains("size"))
                {
                    this->unlock();
                    return -4;
                }
                int size=obj_level1.value("size").toInt();
                if(false==obj_level1.contains("RValue_list"))
                {
                    this->unlock();
                    return -5;
                }
                QJsonArray arry_itemList=obj_level1.value("RValue_list").toArray();

                if(arry_itemList.size()!=size)
                {
                    this->unlock();
                    return -6;
                }
                QString tmpNodeName;
                for(int k=0;k<size;k++)
                {
                    double tmp_value;
                    QJsonObject obj_item=arry_itemList[k].toObject();
                    tmpNodeName="R"+QString::number(k+1);
                    if(false==obj_item.contains(tmpNodeName))
                    {
                        this->unlock();
                        return -100-k;
                    }
                    tmp_value=obj_item[tmpNodeName].toDouble();
                    regRValue.append(tmp_value);
                }


                file.close();
                file.flush();//必须加，如果不加，可能关机的时候丢失文件内容。
            }
            returnFlag= 1;
        }
        else
        {
            regRValue.resize(D_ROBOT_REG_SIZE);
            returnFlag= -1;
        }
        this->unlock();
    }
    return returnFlag;
}

int RegData::setRegRValue(QVector<double> tmpRValue)
{
    if(this->lock())
    {
        regRValue = tmpRValue;
        this->unlock();
    }
    return 1;
}

void RegData::writeRegR2File_stream()
{
    qDebug() << "RegData::writeRegR2File()";
    for(int i = 0; i < regRValue.size();i++)
    {
        //std::cout << "---tmpRValue----"<<regRValue[i]<<std::endl;
    }

    QString tmpName = D_TCRCONTROLLER_DATA_PATH;
    tmpName = tmpName+ROBOT_FLODER + QString::number(robotId);
    QString regRName = tmpName + R_REG_FILE;
    robotName = tmpName;

    qDebug() << "===regRName===="<<regRName<<endl;

    QFile file(regRName);
    if(!file.open(QIODevice::ReadWrite))
    {
        //消息预留
        //保存R寄存器数据到文件失败
    }
    else
    {
        QDataStream out(&file);

        out << regRValue;

        file.close();
        file.flush();//必须加，如果不加，可能关机的时候丢失文件内容。
    }

    MD5Check md5Checker;
    md5Checker.createMd5File(regRName);
}

int RegData::writeRegR2File_json()
{
    qDebug() << "RegData::writeRegR2File_json()";
    this->lock();
    for(int i = 0; i < regRValue.size();i++)
    {
        //std::cout << "---tmpRValue----"<<regRValue[i]<<std::endl;
    }

    QString tmpName = D_TCRCONTROLLER_DATA_PATH;
    tmpName = tmpName+ROBOT_FLODER + QString::number(robotId);
    QString regRName = tmpName + R_REG_FILE;
    robotName = tmpName;

    qDebug() << "===regRName===="<<regRName<<endl;

    QFile file(regRName);
    if(!file.open(QIODevice::WriteOnly| QIODevice::Text))
    {
        //消息预留
        //保存R寄存器数据到文件失败
    }
    else
    {

        QJsonObject obj_root;
        QJsonObject obj_level1;
        QJsonArray arry_itemList;
        obj_level1.insert("size", regRValue.size());

        QString tmpNodeName;
        for(int i=0;i<regRValue.size();i++)
        {
            QJsonObject obj_item;
            tmpNodeName="R"+QString::number(i+1);
            obj_item.insert(tmpNodeName, regRValue[i]);
            arry_itemList.append(obj_item);
        }

        obj_level1.insert("RValue_list", arry_itemList);
        obj_root.insert("regR_info", obj_level1);

        QJsonDocument jsonDoc(obj_root);
        QString tmpString=jsonDoc.toJson();

        //写入内容,这里需要转码，否则报错。
    //    QByteArray str = tmpString.toUtf8();
         QByteArray str = tmpString.toLatin1();
        //写入QByteArray格式字符串
        file.write(str);

        file.close();
        file.flush();//必须加，如果不加，可能关机的时候丢失文件内容。
    }

    this->unlock();

    MD5Check md5Checker;
    md5Checker.createMd5File(regRName);
}

int RegData::readRegPrValue_fromFile()
{
    QString tmpName = D_TCRCONTROLLER_DATA_PATH;
    tmpName = tmpName+ROBOT_FLODER + QString::number(robotId);
    QString regPRName = tmpName + PR_REG_FILE;
    robotName = tmpName;

//     if(1!=readRegPrFile_stream(regPRName))
     if(1!=readRegPrFile_json(regPRName))
     {
         addMsg(ENUM_MSG_ERROR, "RegData", "RegData", 3204, robotId);
         regPrInitialOk=false;
         return -1;
     }
     #ifdef D_USE_MD5_CHECK
     MD5Check md5Checker;
     if(-1==md5Checker.isMd5CheckOk(regPRName,regPRName+".md5"))
     {
         qDebug()<<"readRegRValue checkFile  PR_REG_FILE error！";
         addMsg(ENUM_MSG_ERROR, "RegData", "RegData", 3205, robotId);
         regPrInitialOk=false;

         return -1;
     }
     QFile::remove(regPRName+".md5");
    #endif
     regPrInitialOk=true;
     return 1;

}

int RegData::readRegPrFile_stream(QString fileName)
{

    int returnFlag=-1;
    quint32 tmpSize;

    int tmpInt;
    QString tmpStr;
    float tmpFloat;


    QFile file(fileName);
    if(this->lock())
    {
        if(file.exists())
        {

            if(file.open(QIODevice::ReadOnly))
            {
                QDataStream out(&file);
                out.setVersion(QDataStream::Qt_4_6);
                out >> tmpSize;

                regPrValue.resize(tmpSize);

                for(int i = 0; i < tmpSize;i++)
                {
                    out >> tmpInt;
                    regPrValue[i].jointFlag = tmpInt;
                    out >> tmpInt;
                    regPrValue[i].pointNum = tmpInt;
                    out >> tmpInt;
                    regPrValue[i].groupNum = tmpInt;
                    out >> tmpInt;
                    regPrValue[i].ufValue = tmpInt;
                    out >> tmpInt;
                    regPrValue[i].utValue = tmpInt;
                    out >> tmpInt;
                    regPrValue[i].recordStatus = tmpInt;

                    out >> tmpStr;
                    regPrValue[i].configString = tmpStr.toStdString();

                    out >> tmpInt;
                    regPrValue[i].configInt.resize(tmpInt);
                    for(int j = 0; j < regPrValue[i].configInt.size();j++)
                    {
                        out >> tmpInt;
                        regPrValue[i].configInt[j] = tmpInt;
                    }

                    out >> tmpInt;
                    regPrValue[i].positionValue.resize(tmpInt);
                    for(int j = 0; j < regPrValue[i].positionValue.size();j++)
                    {
                        out >> tmpFloat;
                        regPrValue[i].positionValue[j] = tmpFloat;
                    }

                    out >> tmpInt;
                    regPrValue[i].extPositionValue.resize(tmpInt);
                    for(int j = 0; j < regPrValue[i].extPositionValue.size();j++)
                    {
                        out >> tmpFloat;
                        regPrValue[i].extPositionValue[j] = tmpFloat;
                    }
                }
                file.close();
                file.flush();//必须加，如果不加，可能关机的时候丢失文件内容。
             }
            returnFlag= 1;
        }
        else
        {
            regPrValue.resize(D_ROBOT_REG_SIZE);
            returnFlag= -1;
        }
        this->unlock();
    }
    return returnFlag;
}

int RegData::readRegPrFile_json(QString fileName)
{
    qDebug()<<"RegData::readRegPrFile_json"<<fileName;
    regPrValue.clear();
    int returnFlag=-1;
    QFile file(fileName);
    if(this->lock())
    {
        if(file.exists())
        {
            if(file.open(QIODevice::ReadOnly))
            {

                QByteArray receiveByteArry = file.read(file.bytesAvailable());
                QJsonParseError jsonError;
                QJsonDocument receiveJsonDoc = QJsonDocument::fromJson(receiveByteArry, &jsonError);
                if(jsonError.error != QJsonParseError::NoError )
                {
                  qDebug() << "readRegRFile_json JsonFile error "<<jsonError.error;
                  this->unlock();
                  return -2;
                }
                QJsonObject redeiveJsonObj = receiveJsonDoc.object();

                if(false==redeiveJsonObj.contains("regR_info"))
                {
                    this->unlock();
                    return -3;
                }
                QJsonObject obj_level1=redeiveJsonObj.value("regR_info").toObject();
                if(false==obj_level1.contains("size"))
                {
                    this->unlock();
                    return -4;
                }
                int size=obj_level1.value("size").toInt();
                if(false==obj_level1.contains("RValue_list"))
                {
                    this->unlock();
                    return -5;
                }
                QJsonArray arry_itemList=obj_level1.value("RValue_list").toArray();

                if(arry_itemList.size()!=size)
                {
                    this->unlock();
                    return -6;
                }
                QString tmpNodeName;
                for(int k=0;k<size;k++)
                {
                    PointPro tmp_value;
                    QJsonObject obj_item=arry_itemList[k].toObject();
                    tmpNodeName="PointPro"+QString::number(k+1);
                    if(false==obj_item.contains(tmpNodeName))
                    {
                        this->unlock();
                        return -100-k;
                    }
                    QJsonObject obj_item_point=obj_item[tmpNodeName].toObject();

                    if(1!=getPointProFromJson(obj_item_point,tmp_value))
                    {
                        this->unlock();
                        return -1000-k;
                    }


                    regPrValue.append(tmp_value);
                }


                file.close();
                file.flush();//必须加，如果不加，可能关机的时候丢失文件内容。
            }
            returnFlag= 1;
        }
        else
        {
            regPrValue.resize(D_ROBOT_REG_SIZE);
            returnFlag= -1;
        }
        this->unlock();
    }
    return returnFlag;
}

int RegData::setRegPrValue(QVector<PointPro> tmpPrValue)
{
    if(this->lock())
    {
        regPrValue = tmpPrValue;
        this->unlock();
    }
    return 1;
}

void RegData::writeRegPr2File_stream()
{
    QString tmpName = D_TCRCONTROLLER_DATA_PATH;
    tmpName = tmpName+ROBOT_FLODER + QString::number(robotId);
    QString regPrName = tmpName + PR_REG_FILE;
    robotName = tmpName;

    qDebug() << "===regPrName===="<<regPrName<<endl;

    QFile file(regPrName);
    if(!file.open(QIODevice::ReadWrite))
    {
        //消息预留
        //保存ｐｒ寄存器数据到文件失败
        return;
    }
    else
    {
        QDataStream out(&file);

        out << (quint32)(regPrValue.size());
        for(int i = 0; i < regPrValue.size();++i)
        {
            out << regPrValue[i].jointFlag
                << regPrValue[i].pointNum
                << regPrValue[i].groupNum
                << regPrValue[i].ufValue
                << regPrValue[i].utValue
                << regPrValue[i].recordStatus
                << QString::fromStdString(regPrValue[i].configString);

            out << (quint32)(regPrValue[i].configInt.size());
            for(int j = 0; j < regPrValue[i].configInt.size();j++)
            {
                out << regPrValue[i].configInt[j];
            }

            out << (quint32)(regPrValue[i].positionValue.size());
            for(int j = 0; j < regPrValue[i].positionValue.size();j++)
            {
                out << regPrValue[i].positionValue[j];
            }

            out << (quint32)(regPrValue[i].extPositionValue.size());
            for(int j = 0; j < regPrValue[i].extPositionValue.size();j++)
            {
                out << regPrValue[i].extPositionValue[j];
            }
        }

        file.close();
        file.flush();//必须加，如果不加，可能关机的时候丢失文件内容。
    }

    MD5Check md5Checker;
    md5Checker.createMd5File(regPrName);

}

int RegData::writeRegPr2File_json()
{
    qDebug() << "RegData::writeRegPr2File_json()";
    this->lock();
    for(int i = 0; i < regPrValue.size();i++)
    {
        //std::cout << "---tmpRValue----"<<regRValue[i]<<std::endl;
    }

    QString tmpName = D_TCRCONTROLLER_DATA_PATH;
    tmpName = tmpName+ROBOT_FLODER + QString::number(robotId);
    QString regRName = tmpName + PR_REG_FILE;
    robotName = tmpName;

    qDebug() << "===regRName===="<<regRName<<endl;

    QFile file(regRName);
    if(!file.open(QIODevice::WriteOnly| QIODevice::Text))
    {
        //消息预留
        //保存R寄存器数据到文件失败
    }
    else
    {

        QJsonObject obj_root;
        QJsonObject obj_level1;
        QJsonArray arry_itemList;
        obj_level1.insert("size", regPrValue.size());

        QString tmpNodeName;
        for(int i=0;i<regPrValue.size();i++)
        {
            QJsonObject obj_item;
            tmpNodeName="PointPro"+QString::number(i+1);
            QJsonObject obj_item_point;
            transPointToJson(regPrValue[i],obj_item_point);
            obj_item.insert(tmpNodeName, obj_item_point);
            arry_itemList.append(obj_item);
        }

        obj_level1.insert("RValue_list", arry_itemList);
        obj_root.insert("regR_info", obj_level1);

        QJsonDocument jsonDoc(obj_root);
        QString tmpString=jsonDoc.toJson();

        //写入内容,这里需要转码，否则报错。
    //    QByteArray str = tmpString.toUtf8();
         QByteArray str = tmpString.toLatin1();
        //写入QByteArray格式字符串
        file.write(str);

        file.close();
        file.flush();//必须加，如果不加，可能关机的时候丢失文件内容。
    }

    this->unlock();

    MD5Check md5Checker;
    md5Checker.createMd5File(regRName);
}

int RegData::readRegPlValue_fromFile()
{
    QString tmpName = D_TCRCONTROLLER_DATA_PATH;
    tmpName = tmpName+ROBOT_FLODER + QString::number(robotId);
    QString regPlName = tmpName + PL_REG_FILE;
    robotName = tmpName;


//    if(1!=readRegPlFile_stream(regPlName))
    if(1!=readRegPlFile_json(regPlName))
    {
        addMsg(ENUM_MSG_ERROR, "RegData", "RegData", 3202, robotId);
        regPlInitialOk=false;
        return -1;
    }
    #ifdef D_USE_MD5_CHECK
    MD5Check md5Checker;
    if(-1==md5Checker.isMd5CheckOk(regPlName,regPlName+".md5"))
    {
        qDebug()<<"readRegRValue checkFile PL_REG_FILE error！";
        addMsg(ENUM_MSG_ERROR, "RegData", "RegData", 3203, robotId);
        regPlInitialOk=false;

        return -1;
    }
    QFile::remove(regPlName+".md5");
    #endif
    regPlInitialOk=true;
    return 1;

}

int RegData::readRegPlFile_stream(QString fileName)
{
    int returnFlag=-1;
    quint32 tmpSize;

    QFile file(fileName);
    if(this->lock())
    {
        if(file.exists())
        {
            if(file.open(QIODevice::ReadOnly))
            {
                QDataStream out(&file);
                out.setVersion(QDataStream::Qt_4_6);
                out >> tmpSize;

                regPlValue.resize(tmpSize);

                for(int i = 0; i < tmpSize;i++)
                {
                    out >> regPlValue[i].row;
                    out >> regPlValue[i].col;
                    out >> regPlValue[i].layer;
                }

                file.close();
                file.flush();//必须加，如果不加，可能关机的时候丢失文件内容。
            }
            returnFlag= 1;
        }
        else
        {
            regPlValue.resize(D_ROBOT_REG_SIZE);
            returnFlag= -1;

        }
        this->unlock();
    }

    return returnFlag;
}

int RegData::readRegPlFile_json(QString fileName)
{
    qDebug()<<"RegData::readRegPlFile_json"<<fileName;
    regPlValue.clear();
    int returnFlag=-1;
    QFile file(fileName);
    if(this->lock())
    {
        if(file.exists())
        {
            if(file.open(QIODevice::ReadOnly))
            {

                QByteArray receiveByteArry = file.read(file.bytesAvailable());
                QJsonParseError jsonError;
                QJsonDocument receiveJsonDoc = QJsonDocument::fromJson(receiveByteArry, &jsonError);
                if(jsonError.error != QJsonParseError::NoError )
                {
                  qDebug() << "readRegRFile_json JsonFile error "<<jsonError.error;
                  this->unlock();
                  return -2;
                }
                QJsonObject redeiveJsonObj = receiveJsonDoc.object();

                if(false==redeiveJsonObj.contains("regR_info"))
                {
                    this->unlock();
                    return -3;
                }
                QJsonObject obj_level1=redeiveJsonObj.value("regR_info").toObject();
                if(false==obj_level1.contains("size"))
                {
                    this->unlock();
                    return -4;
                }
                int size=obj_level1.value("size").toInt();
                if(false==obj_level1.contains("RValue_list"))
                {
                    this->unlock();
                    return -5;
                }
                QJsonArray arry_itemList=obj_level1.value("RValue_list").toArray();

                if(arry_itemList.size()!=size)
                {
                    this->unlock();
                    return -6;
                }
                QString tmpNodeName;
                for(int k=0;k<size;k++)
                {
                    PlRegStruct tmp_value;
                    QJsonObject obj_item=arry_itemList[k].toObject();
                    tmpNodeName="row"+QString::number(k+1);
                    if(false==obj_item.contains(tmpNodeName))
                    {
                        this->unlock();
                        return -100-k;
                    }
                    tmp_value.row=obj_item[tmpNodeName].toInt();

                    tmpNodeName="col"+QString::number(k+1);
                    if(false==obj_item.contains(tmpNodeName))
                    {
                        this->unlock();
                        return -100-k;
                    }
                    tmp_value.col=obj_item[tmpNodeName].toInt();

                    tmpNodeName="layer"+QString::number(k+1);
                    if(false==obj_item.contains(tmpNodeName))
                    {
                        this->unlock();
                        return -100-k;
                    }
                    tmp_value.layer=obj_item[tmpNodeName].toInt();

                    regPlValue.append(tmp_value);
                }


                file.close();
                file.flush();//必须加，如果不加，可能关机的时候丢失文件内容。
            }
            returnFlag= 1;
        }
        else
        {
            regPlValue.resize(D_ROBOT_REG_SIZE);
            returnFlag= -1;
        }
        this->unlock();
    }
    return returnFlag;
}

int RegData::setRegPlValue(QVector<PlRegStruct> tmpPlValue)
{
    if(this->lock())
    {
        regPlValue = tmpPlValue;
        this->unlock();
    }
    return 1;
}

void RegData::writeRegPl2File_stream()
{
    std::cout << "****saveREgPl******"<<std::endl;
    QString tmpName = D_TCRCONTROLLER_DATA_PATH;
    tmpName = tmpName+ROBOT_FLODER + QString::number(robotId);
    QString regPlName = tmpName + PL_REG_FILE;
    robotName = tmpName;

    qDebug() << "===regPlName===="<<regPlName<<endl;

    QFile file(regPlName);
    if(!file.open(QIODevice::ReadWrite))
    {
        //消息预留
        //保存ｐｌ寄存器数据到文件失败
        qDebug() << "===regPlName== error=="<<regPlName<<endl;
    }
    else
    {
        QDataStream out(&file);

        out << (quint32)(regPlValue.size());
        for(int i = 0; i < regPlValue.size();++i)
        {
            out << regPlValue[i].row;
            out << regPlValue[i].col;
            out << regPlValue[i].layer;
        }

        file.close();
        file.flush();//必须加，如果不加，可能关机的时候丢失文件内容。
    }

        MD5Check md5Checker;
        md5Checker.createMd5File(regPlName);

}

int RegData::writeRegPl2File_json()
{
    qDebug() << "RegData::writeRegPl2File_json()";
    this->lock();
    for(int i = 0; i < regPlValue.size();i++)
    {
        //std::cout << "---tmpRValue----"<<regRValue[i]<<std::endl;
    }

    QString tmpName = D_TCRCONTROLLER_DATA_PATH;
    tmpName = tmpName+ROBOT_FLODER + QString::number(robotId);
    QString regRName = tmpName + PL_REG_FILE;
    robotName = tmpName;

    qDebug() << "===regRName===="<<regRName<<endl;

    QFile file(regRName);
    if(!file.open(QIODevice::WriteOnly| QIODevice::Text))
    {
        //消息预留
        //保存R寄存器数据到文件失败
    }
    else
    {

        QJsonObject obj_root;
        QJsonObject obj_level1;
        QJsonArray arry_itemList;
        obj_level1.insert("size", regPlValue.size());

        QString tmpNodeName;
        for(int i=0;i<regPlValue.size();i++)
        {
            QJsonObject obj_item;
            tmpNodeName="col"+QString::number(i+1);
            obj_item.insert(tmpNodeName, regPlValue[i].col);

            tmpNodeName="row"+QString::number(i+1);
            obj_item.insert(tmpNodeName, regPlValue[i].row);

            tmpNodeName="layer"+QString::number(i+1);
            obj_item.insert(tmpNodeName, regPlValue[i].layer);

            arry_itemList.append(obj_item);
        }

        obj_level1.insert("RValue_list", arry_itemList);
        obj_root.insert("regR_info", obj_level1);

        QJsonDocument jsonDoc(obj_root);
        QString tmpString=jsonDoc.toJson();

        //写入内容,这里需要转码，否则报错。
    //    QByteArray str = tmpString.toUtf8();
         QByteArray str = tmpString.toLatin1();
        //写入QByteArray格式字符串
        file.write(str);

        file.close();
        file.flush();//必须加，如果不加，可能关机的时候丢失文件内容。
    }

    this->unlock();

    MD5Check md5Checker;
    md5Checker.createMd5File(regRName);
}

int RegData::readRegTimerValue_fromFile()
{
    QString tmpName = D_TCRCONTROLLER_DATA_PATH;
    tmpName = tmpName+ROBOT_FLODER + QString::number(robotId);
    QString regTimerName = tmpName + TIMER_REG_FILE;
    robotName = tmpName;

//    if(1!=readRegTimerFile_stream(regTimerName))
    if(1!=readRegTimerFile_json(regTimerName))
    {
        addMsg(ENUM_MSG_ERROR, "RegData", "RegData", 3206, robotId);
        regTimerInitialOk=false;
        return -1;
    }
    #ifdef D_USE_MD5_CHECK
    MD5Check md5Checker;
    if(-1==md5Checker.isMd5CheckOk(regTimerName,regTimerName+".md5"))
    {
        qDebug()<<"readRegRValue checkFile  TIMER_REG_FILE error！";
        addMsg(ENUM_MSG_ERROR, "RegData", "RegData", 3207, robotId);
        regTimerInitialOk=false;
        return -1;
    }
    QFile::remove(regTimerName+".md5");
    #endif
    regTimerInitialOk=true;
    return 1;
}

int RegData::readRegTimerFile_stream(QString fileName)
{
    int returnFlag=-1;
    QFile file(fileName);
    if(this->lock())
    {
        if(file.exists())
        {
            if(file.open(QIODevice::ReadOnly))
            {
                QDataStream out(&file);
                out.setVersion(QDataStream::Qt_4_6);
                out >> regTimerValue;
                file.close();
                file.flush();//必须加，如果不加，可能关机的时候丢失文件内容。
            }
            returnFlag=1;
        }
        else
        {
            regTimerValue.resize(D_ROBOT_REG_SIZE);
            returnFlag=-1;
        }
        this->unlock();
    }
    return returnFlag;
}

int RegData::readRegTimerFile_json(QString fileName)
{
    qDebug()<<"RegData::readRegTimerFile_json"<<fileName;
    regTimerValue.clear();
    int returnFlag=-1;
    QFile file(fileName);
    if(this->lock())
    {
        if(file.exists())
        {
            if(file.open(QIODevice::ReadOnly))
            {

                QByteArray receiveByteArry = file.read(file.bytesAvailable());
                QJsonParseError jsonError;
                QJsonDocument receiveJsonDoc = QJsonDocument::fromJson(receiveByteArry, &jsonError);
                if(jsonError.error != QJsonParseError::NoError )
                {
                  qDebug() << "readRegRFile_json JsonFile error "<<jsonError.error;
                  this->unlock();
                  return -2;
                }
                QJsonObject redeiveJsonObj = receiveJsonDoc.object();

                if(false==redeiveJsonObj.contains("regR_info"))
                {
                    this->unlock();
                    return -3;
                }
                QJsonObject obj_level1=redeiveJsonObj.value("regR_info").toObject();
                if(false==obj_level1.contains("size"))
                {
                    this->unlock();
                    return -4;
                }
                int size=obj_level1.value("size").toInt();
                if(false==obj_level1.contains("RValue_list"))
                {
                    this->unlock();
                    return -5;
                }
                QJsonArray arry_itemList=obj_level1.value("RValue_list").toArray();

                if(arry_itemList.size()!=size)
                {
                    this->unlock();
                    return -6;
                }
                QString tmpNodeName;
                for(int k=0;k<size;k++)
                {
                    double tmp_value;
                    QJsonObject obj_item=arry_itemList[k].toObject();
                    tmpNodeName="Timer"+QString::number(k+1);
                    if(false==obj_item.contains(tmpNodeName))
                    {
                        this->unlock();
                        return -100-k;
                    }
                    tmp_value=obj_item[tmpNodeName].toDouble();
                    regTimerValue.append(tmp_value);
                }


                file.close();
                file.flush();//必须加，如果不加，可能关机的时候丢失文件内容。
            }
            returnFlag= 1;
        }
        else
        {
            regTimerValue.resize(D_ROBOT_TIMER_REG_SIZE);
            returnFlag= -1;
        }
        this->unlock();
    }
    return returnFlag;
}

int RegData::getPointProFromJson(const QJsonObject &obj_item_point, PointPro &pointOut)
{
    PointPro tmpPoint;
    if(false==obj_item_point.contains("jointFlag"))
    {

        return -1;
    }
    tmpPoint.jointFlag=obj_item_point.value("jointFlag").toInt();
    if(false==obj_item_point.contains("pointNum"))
    {

        return -2;
    }
    tmpPoint.pointNum=obj_item_point.value("pointNum").toInt();
    if(false==obj_item_point.contains("groupNum"))
    {

        return -3;
    }
    tmpPoint.groupNum=obj_item_point.value("groupNum").toInt();
    if(false==obj_item_point.contains("ufValue"))
    {

        return -4;
    }
    tmpPoint.ufValue=obj_item_point.value("ufValue").toInt();
    if(false==obj_item_point.contains("utValue"))
    {

        return -5;
    }
    tmpPoint.utValue=obj_item_point.value("utValue").toInt();
    if(false==obj_item_point.contains("recordStatus"))
    {

        return -6;
    }
    tmpPoint.recordStatus=obj_item_point.value("recordStatus").toInt();
    if(false==obj_item_point.contains("configString"))
    {

        return -7;
    }
    tmpPoint.configString=obj_item_point.value("configString").toString().toStdString();
    //
    if(false==obj_item_point.contains("configInt"))
    {

        return -8;
    }
    QJsonArray tmp_arry=obj_item_point.value("configInt").toArray();
    for(int i=0;i<tmp_arry.size();i++)
    {
        tmpPoint.configInt.push_back(tmp_arry[i].toInt());
    }
    //
    if(false==obj_item_point.contains("positionValue"))
    {

        return -9;
    }
    tmp_arry=obj_item_point.value("positionValue").toArray();
    for(int i=0;i<tmp_arry.size();i++)
    {
        tmpPoint.positionValue.push_back(tmp_arry[i].toDouble());
    }

    //
    if(false==obj_item_point.contains("extPositionValue"))
    {

        return -10;
    }
    tmp_arry=obj_item_point.value("extPositionValue").toArray();
    for(int i=0;i<tmp_arry.size();i++)
    {
        tmpPoint.extPositionValue.push_back(tmp_arry[i].toDouble());
    }
    pointOut=tmpPoint;
    return 1;

}

int RegData::transPointToJson(const PointPro &pointIn, QJsonObject &obj_out)
{
    QJsonObject obj_item_point;
    obj_item_point.insert("jointFlag", pointIn.jointFlag);
    obj_item_point.insert("pointNum", pointIn.pointNum);
    obj_item_point.insert("groupNum", pointIn.groupNum);
    obj_item_point.insert("ufValue", pointIn.ufValue);
    obj_item_point.insert("utValue", pointIn.utValue);
    obj_item_point.insert("recordStatus", pointIn.recordStatus);
    obj_item_point.insert("configString", QString::fromStdString(pointIn.configString));


    QJsonArray arry_configInt,arry_positionValue,arry_extPositionValue;

    for(int i=0;i<pointIn.configInt.size();i++)
    {
        arry_configInt.append(QJsonValue(pointIn.configInt[i]));
    }
    obj_item_point.insert("configInt", arry_configInt);

    for(int i=0;i<pointIn.positionValue.size();i++)
    {
        arry_positionValue.append(QJsonValue(pointIn.positionValue[i]));
    }
    obj_item_point.insert("positionValue", arry_positionValue);

    for(int i=0;i<pointIn.extPositionValue.size();i++)
    {
        arry_extPositionValue.append(QJsonValue(pointIn.extPositionValue[i]));
    }
    obj_item_point.insert("extPositionValue", arry_extPositionValue);

    obj_out=obj_item_point;
    return 1;

}

int RegData::updateTimerRegisterValue()
{
    for(int i = 0; i < regTimerValue.size();i++)
    {
        if(TIMER_REG_PROCESS_STOP != timerProcessType[i])
        {
            updateTimerRegisterValue_index(i);
        }
    }

    return 1;
}

int RegData::setRegTimerValue(QVector<double> tmpTimerValue)
{
    if(this->lock())
    {
        regTimerValue = tmpTimerValue;
        this->unlock();
    }
    return 1;
}

void RegData::writeRegTimer2File_stream()
{
    qDebug() << "RegData::writeRegTimer2File()";
    for(int i = 0; i < regTimerValue.size();i++)
    {
        //std::cout << "---tmpRValue----"<<regTimerValue[i]<<std::endl;
    }

    QString tmpName = D_TCRCONTROLLER_DATA_PATH;
    tmpName = tmpName+ROBOT_FLODER + QString::number(robotId);
    QString regTimerName = tmpName + TIMER_REG_FILE;
    robotName = tmpName;

    qDebug() << "===regTimerName===="<<regTimerName<<endl;

    QFile file(regTimerName);
    if(!file.open(QIODevice::ReadWrite))
    {
        //消息预留
        //保存R寄存器数据到文件失败
    }
    else
    {
        QDataStream out(&file);

        out << regTimerValue;

        file.close();
        file.flush();//必须加，如果不加，可能关机的时候丢失文件内容。
    }

    MD5Check md5Checker;
    md5Checker.createMd5File(regTimerName);
}

int RegData::writeRegTimer2File_json()
{
    qDebug() << "RegData::writeRegTimer2File_json()";
    this->lock();
    for(int i = 0; i < regTimerValue.size();i++)
    {
        //std::cout << "---tmpRValue----"<<regRValue[i]<<std::endl;
    }

    QString tmpName = D_TCRCONTROLLER_DATA_PATH;
    tmpName = tmpName+ROBOT_FLODER + QString::number(robotId);
    QString regRName = tmpName + TIMER_REG_FILE;
    robotName = tmpName;

    qDebug() << "===regRName===="<<regRName<<endl;

    QFile file(regRName);
    if(!file.open(QIODevice::WriteOnly| QIODevice::Text))
    {
        //消息预留
        //保存R寄存器数据到文件失败
    }
    else
    {

        QJsonObject obj_root;
        QJsonObject obj_level1;
        QJsonArray arry_itemList;
        obj_level1.insert("size", regTimerValue.size());

        QString tmpNodeName;
        for(int i=0;i<regTimerValue.size();i++)
        {
            QJsonObject obj_item;
            tmpNodeName="Timer"+QString::number(i+1);
            obj_item.insert(tmpNodeName, regTimerValue[i]);
            arry_itemList.append(obj_item);
        }

        obj_level1.insert("RValue_list", arry_itemList);
        obj_root.insert("regR_info", obj_level1);

        QJsonDocument jsonDoc(obj_root);
        QString tmpString=jsonDoc.toJson();

        //写入内容,这里需要转码，否则报错。
    //    QByteArray str = tmpString.toUtf8();
         QByteArray str = tmpString.toLatin1();
        //写入QByteArray格式字符串
        file.write(str);

        file.close();
        file.flush();//必须加，如果不加，可能关机的时候丢失文件内容。
    }

    this->unlock();

    MD5Check md5Checker;
    md5Checker.createMd5File(regRName);
}

void RegData::writeAllReg_toFile()
{
//    writeRegPl2File_stream();
    writeRegPl2File_json();
//    writeRegPr2File_stream();
    writeRegPr2File_json();
//    writeRegR2File_stream();
    writeRegR2File_json();
//    writeRegTimer2File_stream();
     writeRegTimer2File_json();
}

int RegData::clearPlReg(int plNum)
{

    if(this->lock())
    {
        if(plNum<0 || plNum>=regPlValue.size())
        {
            this->unlock();
            return -1;
        }
        PlRegStruct tmpPlReg;
        tmpPlReg.row = 0;
        tmpPlReg.col = 0;
        tmpPlReg.layer = 0;

        regPlValue[plNum] = tmpPlReg;
        this->unlock();
    }
    return 1;
}

int RegData::getPlRegister(int plNum, PlRegStruct &valueOut)
{

    if(this->lock())
    {
        if(plNum<0 || plNum>=regPlValue.size())
        {
            this->unlock();
            return -1;
        }

        valueOut=regPlValue[plNum];
        this->unlock();
    }
    return 1;
}

int RegData::clearTimerReg(int timerNum)
{
    if(this->lock())
    {
        if(timerNum<0 || timerNum>=regTimerValue.size())
        {
            this->unlock();
            return -1;
        }
        regTimerValue[timerNum] = 0.0;
        this->unlock();
    }
    return 1;
}

int RegData::setPlRegValue(int plNum, PlRegStruct plReg)
{
    if(this->lock())
    {
        if(plNum<0 || plNum>=regPlValue.size())
        {
            this->unlock();
            return -1;
        }
        regPlValue[plNum] = plReg;
        this->unlock();
    }
    return 1;
}

int RegData::setTimerRegValue(int timerNum, double timerReg)
{
    if(this->lock())
    {
        if(timerNum<0 || timerNum>=regTimerValue.size())
        {
            this->unlock();
            return -1;
        }
        regTimerValue[timerNum] = timerReg;
        this->unlock();
    }
    return 1;
}

void RegData::clearAllTimerValue()
{
    if(this->lock())
    {
        regTimerValue.resize(D_ROBOT_REG_SIZE);
        regTimerValue.fill(0);
        this->unlock();
    }
//    writeRegTimer2File_stream();
    writeRegTimer2File_json();
    regTimerInitialOk=true;
}

void RegData::clearAllPlValue()
{
    if(this->lock())
    {
        regPlValue.clear();
        regPlValue.resize(D_ROBOT_REG_SIZE);
        this->unlock();
    }
//    writeRegPl2File_stream();
    writeRegPl2File_json();
    regPlInitialOk=true;
}

void RegData::clearAllPrValue()
{
    if(this->lock())
    {
        regPrValue.clear();
        regPrValue.resize(D_ROBOT_REG_SIZE);
        this->unlock();
    }
//    writeRegPr2File_stream();
    writeRegPr2File_json();
    regPrInitialOk=true;
}

void RegData::clearAllRegRValue()
{
    if(this->lock())
    {
        regRValue.resize(D_ROBOT_REG_SIZE);
        regRValue.fill(0);
        this->unlock();
    }
//    writeRegR2File_stream();
    writeRegR2File_json();
    regRInitialOk=true;
}

int RegData::setRRegValue(int number, double rValue)//index  从０开始
{

    if(this->lock())
    {
        if(0>number || regRValue.size()<=number)
        {
            this->unlock();
            return -1;
        }
        regRValue[number] = rValue;
//        qDebug() <<__FUNCTION__<<"===number==="<<number<<"==rValue==="<<rValue;
        this->unlock();
    }
    return 1;
}

int RegData::getRRegValue(int number, double &rValueOut)//index  从０开始
{
    if(this->lock())
    {
        if(0>number || regRValue.size()<=number)
        {
            this->unlock();
            return -1;
        }
        rValueOut=regRValue[number];

        this->unlock();
    }
    return 1;
}



int RegData::setPrRegValue(int number, PointPro pointPro)
{
    if(this->lock())
    {
        if(0>number || regPrValue.size()<=number)
        {
            this->unlock();
            return -1;
        }
        pointPro.configString.clear();//不使用多圈多解信息。
        pointPro.pointNum=-1;
        pointPro.ufValue=-1;
        pointPro.utValue=-1;
        regPrValue[number] = pointPro;
        this->unlock();
    }
    return 1;
}

int RegData::setPrRegValueType(int number, bool isCoordinatePoint)
{
    if(this->lock())
    {
        if(0>number || regPrValue.size()<=number)
        {
            this->unlock();
            return -1;
        }
        regPrValue[number].jointFlag = isCoordinatePoint;
        this->unlock();
    }
    return 1;
}

int RegData::getPrValue(int index, PointPro &pointPro)
{
    if(this->lock())
    {
        if(0>index || regPrValue.size()<=index)
        {
            this->unlock();
            return -1;
        }
        pointPro = regPrValue[index];
        this->unlock();
    }
    return 1;
}

int RegData::getPrValue_ij(int index_i, int index_j, double &valueOut)
{
    if(this->lock())
    {
        if(0>index_i || regPrValue.size()<=index_i)
        {
            this->unlock();
            return -1;
        }
        if(0>index_j || regPrValue[index_i].positionValue.size()<=index_j)
        {
            this->unlock();
            return -1;
        }
        valueOut = regPrValue[index_i].positionValue[index_j];
        this->unlock();
    }
    return 1;
}

int RegData::setPrIJValue(int num_i, int num_j, double position)
{
    if(this->lock())
    {
        if(0>num_i || regPrValue.size()<=num_i)
        {
            this->unlock();
            return -1;
        }

        if(0>num_j )
        {
            this->unlock();
            return -2;
        }
        else if( regPrValue[num_i].positionValue.size()<=num_j)
        {
            regPrValue[num_i].positionValue.resize(num_j+1);
        }
        regPrValue[num_i].positionValue[num_j] = position;
        this->unlock();
    }
    return 1;
}

QVector<double> RegData::returnRValue(bool& initialStatus)
{
     if(this->lock())
     {
         QVector <double> rValue = regRValue;
         this->unlock();
         initialStatus=regRInitialOk;
         return rValue;
     }
}

QVector<PointPro> RegData::returnPrValue(bool& initialStatus)
{
    if(this->lock())
    {
        QVector <PointPro> prValue = regPrValue;
        this->unlock();
        initialStatus=regPrInitialOk;
        return prValue;
    }
}

QVector<PlRegStruct> RegData::returnPlValue(bool &initialStatus)
{
    if(this->lock())
    {
        QVector <PlRegStruct> plValue = regPlValue;
        this->unlock();
        initialStatus=regPlInitialOk;
        return plValue;
    }
}

QVector<double> RegData::returnTimerValue(bool &initialStatus)
{
    if(this->lock())
    {
        QVector <double> timerValue = regTimerValue;
        this->unlock();
        initialStatus=regTimerInitialOk;
        return timerValue;
    }
}


int RegData::addMsg(int messageLevel, string componentName, string messageType,
                           int messageCode, int robotIdIn,
                           int parameter1, int parameter2, int parameter3, int parameter4)
{
    Message tmpMsg;
    tmpMsg.MessageLevel = messageLevel;
    tmpMsg.componentClassName = componentName;
    tmpMsg.messageType = messageType;
    tmpMsg.robotId = robotIdIn;
    tmpMsg.messageCode = messageCode;
   // tmpMsg.time = t1.tv_sec;


    QString infomationStr;

    switch(messageCode)
    {
    case 3208:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotIdIn) ;
        infomationStr = infomationStr + QObject::tr(",启动方式不支持，请修改！ ");
    }
        break;
    case 3207:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotIdIn) ;
        infomationStr = infomationStr + QObject::tr(",TIMER寄存器文件校验错误！ ");
    }
        break;

    case 3206:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotIdIn)  ;
        infomationStr = infomationStr  + QObject::tr(",TIMER寄存器文件找不到！ ");
    }
        break;
    case 3205:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotIdIn) ;
        infomationStr = infomationStr + QObject::tr(",PR寄存器文件校验错误！ ");
    }
        break;

    case 3204:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotIdIn)  ;
        infomationStr = infomationStr  + QObject::tr(",PR寄存器文件找不到！ ");
    }
        break;
    case 3203:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotIdIn) ;
        infomationStr = infomationStr + QObject::tr(",PL寄存器文件校验错误！ ");
    }
        break;

    case 3202:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotIdIn)  ;
        infomationStr = infomationStr  + QObject::tr(",PL寄存器文件找不到！ ");
    }
        break;
    case 3201:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotIdIn)  ;
        infomationStr = infomationStr + QObject::tr(",R寄存器文件校验错误！ ");
    }
        break;

    case 3200:
    {
        infomationStr =  QObject::tr("机器人:")  + QString::number(robotIdIn)  ;
        infomationStr = infomationStr  + QObject::tr(",R寄存器文件找不到！ ");
    }
        break;

    }

    tmpMsg.MessageInformation = infomationStr.toStdString();

    MessageLog::getInstance()->addMessage(tmpMsg);
}

